<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@ page import="java.util.List"%>
<%@ page isELIgnored="false" %> <%--isELIgnored=true禁用EL表达式--%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="<%=request.getContextPath() %>/layui-v2.6.13/layui/css/layui.css" />
		<script src="<%=request.getContextPath() %>/layui-v2.6.13/layui/layui.js"></script>
		<script src="<%=request.getContextPath() %>/js/jquery.min-2.1.1.js"></script>
	</head>
	<script>

	function updateSubmit(id){
			var params = $("#updateForm").serialize();
			params += "&id="+id;
			console.info(params);

			$.ajax({
				url:"update",
				data:params,
				type:"POST",
				success:function(str){
					if(str=="1"){
						alert("更新成功!!!!");

					}else{
						alert("更新失败!!!!");

					}
					setTimeout(closeLayer(),500);

				}
			});
		}

	function closeLayer(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
		window.parent.location.reload();
	}
	</script>
	<body>
		<form class="layui-form" action="" id="updateForm">

			<div class="layui-form-item">
				<div class="layui-input-inline" style="width: 48%;">
					<input type="text"  placeholder="商品名称" class="layui-input"  name="gName" value="${obj.gName}">
				</div>
			</div>
			<div class="layui-form-item">
				<div style="width: 48%;">
					<input type="text"  placeholder="库存" class="layui-input" name="gCount" value="${obj.gCount}">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-inline" style="width: 48%;">
					<input type="text" placeholder="单价" class="layui-input"  name="gPrice" value="${obj.gPrice}">
				</div>
			</div>
			<div class="layui-form-item" style="width: 48%;">
				<select class="layui-select" name="sId">
					<option>分类</option>
					<c:forEach items="${sort}" var="sort">
					    <option <c:if test="${obj.sId == sort.sortId}">selected=true</c:if>
                        value="${sort.sortId}">${sort.sName}</option>
					</c:forEach>
				</select>
			</div>
			<div class="layui-form-item">
			    <div class="layui-inline">
                    <input type="text" name="imgUrl" class="layui-input" id="text" readonly="realonly" value="${obj.imgUrl}" style="width:355px">
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn" id="imgUpload">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
            <div>
		<button type="reset" class="layui-btn layui-btn-primary" style="width: 48%;">重置</button>
		</form>
		<div>
		    <button class="layui-btn" lay-submit lay-filter="formDemo" style="width: 48%;" onclick="updateSubmit(${obj.id})">立即提交</button>
        </div>

		<script>
			//Demo
			layui.use('form', function() {
				var form = layui.form;

				//提交
				form.on('submit(formDemo)', function(data) {
					//layer.msg(JSON.stringify(data.field));
					return false;
				});
			});





			layui.use('upload', function(){
                var upload = layui.upload;

                //执行实例
                upload.render({
                    elem: '#imgUpload' //绑定元素
                    ,url: 'upload' //上传接口
                    ,accept: 'images' //指定允许上传时校验的文件类型，可选值有：images（图片）、file（所有文件）、video（视频）、audio（音频）
                    ,acceptMime: 'image/*' //规定打开文件选择框时，筛选出的文件类型，值为用逗号隔开的 MIME 类型列表
                    ,done: function(res){//上传完毕回调,res必须是json格式
                        console.info(res);
                        console.info(res.imgUrl);
                        var img=$("#imgUrl");
                        var text=$("#text");
                        text.val(res.imgUrl);
                        img.val(res.imgUrl);
                        console.info("img的值"+img.val());
                        console.info("text的值"+text.val());

                    }
                    ,error: function(){
                        //请求异常回调
                    }
                });
            });

		</script>




</body>
</html>